import Ember from 'ember';
// import Pinyin from "npm:pinyin";

export default Ember.Route.extend({
  dataService: Ember.inject.service("date-service"),
  beforeModel:function(transition){
    console.log("location first:" + window.location.href);
    //第一次必须只访问index页面(移动端)
    if(this.get("global_curStatus").get("isMobile")){
      var href = window.location.href;
      if(href.indexOf("business")>0){
        console.log("need reindex");
        // transition.abort();
        this.get("global_curStatus").toIndexPage();
        return;
      }
    }
    console.log("today timestamp:" + this.get("dataService").getTodayTimestamp());
    console.log("7day timestamp:" + this.get("dataService").getDaysBeforeTimestamp(7));
    this.sendPost();
  },
  makeCall: function(phone) {
    var curUser = this.get("global_curStatus").getUser();
    // this.store.createRecord('user', {
    //   address: curUser.get("address"),
    //   age: curUser.get("age"),
    //   phone: curUser.get("phone"),
    //   weixin: curUser.get("weixin"),
    //   email: curUser.get("email"),
    //   descdesc: curUser.get("desc"),
    //   introduce: curUser.get("introduce"),
    // }).save();
    // entity.save();
    this.store.findRecord('user',1).then(function(user){
      console.log("user get",user);
      user.set("code","test");
      // user.set("extendInfo",null);
      // user.set("cstag",null);
      // user.set("language",null);
      user.save();
    });
  },
  sendQuery: function(){
    this.store.query("userTask",{filter:{user:{id:1}}});
  },
  sendPost: function(){
    // $.ajax({
    //   type: "OPTIONS",
    //   url: "http://localhost:9080/api/task/1",
    //   data: { name: "John", location: "Boston" }
    // });

  },
  createUser: function(){
    var saveLocalAction = function(userLocal){
      userLocal.set("loginName","111");
      userLocal.set("password","222");
      userLocal.set("current",1);
      userLocal.save().then(function(){
        console.log("save local ok");
      });
    };
    var userLocalEmpty = this.store.createRecord("localstorage/user");
    saveLocalAction(userLocalEmpty);
  },
  afterModel: function(model,transition) {
    console.log("after model in");
  }
});
